package top.houry.sort;

/**
 * @Desc
 * @Author houruiyang
 * @Date 2022/9/28
 **/
public class QuickSort {

    public static void main(String[] args) {
        int[] array = {1,3,6,5,3,1};
        quickSort22(array, 0, array.length - 1);

        for (int i : array) {
            System.out.print(i + ",");
        }
    }


    private static void quickSort22(int[] array, int begin, int end) {
        if (begin >= end) {
            return;
        }
        int pivot = array[begin];

        int left = begin;
        int right = end;

        while (left <= right) {
            while (left <= right && array[right] > pivot) {
                right--;
            }

            while ((left <= right) && array[left] < pivot) {
                left++;
            }
            if (left <= right) {
                int temp = array[left];
                array[left] = array[right];
                array[right] = temp;
                left++;
                right--;
            }
        }

        quickSort22(array, begin, left);
        quickSort22(array, right, end);
    }
}
